package com.xzx.paymentdemo.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.jws.HandlerChain;
import java.util.HashMap;
import java.util.Map;

/**
 * 统一相应结果
 *
 * @author xzx
 * @since 2022/5/29
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class R {

    private Integer code; //响应码
    private String message; //响应消息
    private Map<String, Object> data = new HashMap<>();

    public static R ok(){
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(400);
        r.setMessage("失败");
        return r;
    }

    public R data(String key, Object value){
        this.data.put(key, value);
        return this;
    }
//    public static R success(String message) {
//        return new R(200, message, null);
//    }
//
//    public static R success(String message, Map<String, Object> data) {
//        return new R(200, message, data);
//    }
//
//    public static R error(String message) {
//        return new R(500, message, null);
//    }
//
//    public static R error(String message, Map<String, Object> data) {
//        return new R(500, message, data);
//    }
}
